package com.bilibili.server.controller;

import com.bilibili.model.vo.ContactVo;
import com.bilibili.model.vo.PageResult;
import com.bilibili.model.vo.UserInfoVo;
import com.bilibili.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author HuangRongFu
 * 2021/11/23 星期二1:12 下午
 */

@RequestMapping("/messages")
@RestController
public class MessagesController {

    @Autowired
    private MessagesService movementService;


    /**
     * 根据环信id查询用户信息
     * @param:  huanXinId
     * @Return: ResponseEntity
     */
    @GetMapping("/userinfo")
    public ResponseEntity findUserInfo(@RequestParam(value = "huanxinId")String huanXinId){

        UserInfoVo vo = movementService.findUserInfo(huanXinId);

        return ResponseEntity.ok(vo);
    }

    /**
     * 添加联系人
     * @param:  userId
     * @Return: ResponseEntity
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map<String, Integer> paramMap){

        Long userId = Long.valueOf(paramMap.get("userId").toString());
        movementService.addContacts(userId);

        return ResponseEntity.ok(null);
    }

    /**
     * 联系人列表
     * @param:  page
     * @param:  pageSize
     * @param:  heyWord
     * @Return: ResponseEntity
     */
    @GetMapping("/contacts")
    public ResponseEntity contactsList(@RequestParam(value = "page", defaultValue = "1")Long page,
                                       @RequestParam(value = "pagesize", defaultValue = "10")Long pageSize,
                                       String keyword){

        PageResult<ContactVo> pageResult = movementService.findContact(page, pageSize, keyword);

        return ResponseEntity.ok(pageResult);
    }
}
